package com.example.personalserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.personalserver.entity.user;
import com.example.personalserver.service.userService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@CrossOrigin
@RequestMapping("/user")
//controller层处理登录注册逻辑
public class User {
    private final userService userService;

    public User(com.example.personalserver.service.userService userService) {
        this.userService = userService;
    }

    /*
    登录
     * @param username
      * @param password
      * @return 在数据库中使用userService进行查询，登录成功返回用户信息，失败返回null
     */
    @PostMapping("/login")
    public user login(String username, String password) {
        //构造一个wrapper，使用lamda::
        QueryWrapper<user> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(user::getUsername, username).eq(user::getPassword, password);
        return userService.getOne(wrapper);
    }

}
